<?php
header('Content-Type:text/html; Charset=UTF-8');
require 'lib/checker.php';

@$name = $_REQUEST['name'];
@$price = $_REQUEST['price'];
@$type = $_REQUEST['type'];
@$img = $_FILES['img'];

$title = '添加菜品错误提示';
$jumpUrl = 'dishAdd.php';

var_dump($name);
var_dump($price);
var_dump($type);
var_dump($img);

if($img['error']!=0){
	$mesage = '菜品的照片上传出错';
	include 'lib/message.php';
	die;
}

if(empty($name)){
	$message = '菜品名必须填写';
	include 'lib/message.php';
	die;
}

if(empty($price)){
	$message = '菜品价格必须选定';
	include 'lib/message.php';
	die;
}

if(empty($type)){
	$message = '菜品类型必须选定';
	include 'lib/message.php';
	die;
}

if(empty($img['name'])){
	$message = '菜品图片必须选定';
	include 'lib/message.php';
	die;
}

$flag = move_uploaded_file($img['tmp_name'], 'imgs/'.$img['name']);
if(!$flag){
	$mesage = '菜品照片上传失败';
	include 'lib/message.php';
	die;
}

require 'lib/db.php';

@$type = dbSelect('select id,name from type where name=:name',array('name'=>$type));

var_dump($type['id']);

@$flag = dbInsert('insert into entry(name,imgUrl,price,type_id) values (:name,:imgUrl,:price,:type_id)',array('name'=>$name,'imgUrl'=>$img['name'],'price'=>$price,'type_id'=>$type['id']));

if(!$flag){
	$message = '添加菜品失败';
	include 'lib/message.php';
	die;
}

header('location:dishList.php');
